package com.yunquan.ohana.entity

import java.io.Serializable

data class FramesEntity(
    val id: String?,
    var name: String?,
    var roomLocation: String?,
    var online: Boolean?,
    var deviceRoleVo: FramesRoleEntity? = null,
    var memberDictVo: FramesMemberEntity? = null,
    var check: Boolean = false,
) : Serializable

data class FramesRoleEntity(
    var id: String? = null,
    var deviceId: String? = null,
    var userId: String? = null,
    var email: String? = null,
    var account: String? = null,
    var password: String? = null,
    // 是否绑定1:本人绑定，3：他人绑定，2为空
    var type: Int? = null,
    var name: String? = null,
    var backgroundColor: String? = null,
)

data class FramesMemberEntity(
    var id: String? = null,
    var dictType: String? = null,
    var dictName: String? = null,
    var dictValue: String? = null,
    var roleNum: Int? = null,
    var remark: String? = null,
)

data class GroupFramesEntity(
    val deviceId: String?,
    val id: String?,
    val name: String?,
    val online: Boolean?,
    val receipt: Boolean?,
    val roomLocation: String?,
)

class FramesDataManager {

    companion object {
        val instance by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { FramesDataManager() }
    }

    private val frames = mutableListOf<FramesEntity>()

    fun setData(data: List<FramesEntity>) {
        frames.clear()
        frames.addAll(data)
    }

    fun getData(): List<FramesEntity> {
        return frames.sortedByDescending { it.online }
    }

    fun queryById(id: String): FramesEntity? {
        return frames.find { it.id == id }
    }

    fun removerAt(id: String) {
        frames.removeIf { it.id == id }
    }

    fun clear() {
        frames.clear()
    }
}